package org.saxion.concurrency

import scala.actors.Actor
import scala.actors.Actor._

class Developer(secretary: Actor, name: String) extends Actor {
  def act() {
    println(name + " is alive")
    loop {
      Thread.sleep(((scala.math.random) * 1000).toLong);
      println(name + " is asking for meeting")
      secretary ! AskForMeeting
      react {
        case WaitForMeeting =>
          println(name + " is waiting for meeting");
          receive {
            case GoBackToWork =>
              println(name + " is going back to work");
              Thread.sleep(((scala.math.random) * 1000).toLong);
            case BeginMeeting =>
              println(name + " at meeting");
              receive {
                case EndMeeting =>
                  println(name + " has ended the meeting");
                  Thread.sleep(((scala.math.random) * 1000).toLong);
              }
          }
      }
    }
  }
  def getName() = name;
}